library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.4     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.3     ✓ stringr 1.4.0
## ✓ readr   2.0.2     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(dplyr)
library(ggridges)
library(ggplot2)
library(forcats)
library(p8105.datasets)
library(httr)
library(jsonlite)
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
library(viridis)
## Loading required package: viridisLite
library(patchwork)
library(knitr)    
library(png)
library(tidyverse)
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:httr':
## 
##     config
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(p8105.datasets)
data("rest_inspec")


rest_inspec=janitor::clean_names(rest_inspec)
rest_inspec<-filter(rest_inspec, boro %in% c("MANHATTAN", "BRONX", "QUEENS","BROOKLYN","STATEN ISLAND"))
rest_inspec<-na.omit(rest_inspec)
critical<-filter(rest_inspec,critical_flag %in% c("Critical"),  boro %in% c("MANHATTAN", "BRONX", "QUEENS","BROOKLYN","STATEN ISLAND"))
Manhattan<-filter(rest_inspec, boro %in% c("MANHATTAN"))
rest_inspec %>% 
  mutate(boro = fct_reorder(boro, score)) %>% 
  plot_ly(y = ~score, color = ~boro, type = "box", colors = "viridis")
fig <- plot_ly(
  type = 'scatter',
  x = rest_inspec$cuisine_description,
  y = rest_inspec$score,
  mode = 'markers',
  transforms = list(
    list(
      type = 'aggregate',
      groups = rest_inspec$cuisine_description,
      aggregations = list(
        list(
          target = 'y', func = 'sum', enabled = T
        )
      )
    )
  )
)

fig
critical%>% 
  count(cuisine_description) %>% 
  mutate(boro= fct_reorder(cuisine_description, n)) %>% 
  plot_ly(x = ~cuisine_description, y = ~n, color = ~cuisine_description, type = "bar", colors = "viridis")